// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-18

package v2

import (
	"context"
	"time"
)

// Process is an interface for managing the lifecycle of virtual processes. It's
// work like a process of os.
type Process interface {
	// Add means adding multiple child processes to the current process.
	Add(children ...Process) Process

	// Del means deleting multiple child processes from the current
	// process.
	Del(children ...Process) Process

	// GetChild returns a child process with given name if exists other nil
	// returned.
	GetChild(name string) (p Process, exists bool)

	// GetName return the process name.
	GetName() string

	// GetUid returns the process unique id.
	GetUid() string

	// Prevent to remove from parent when current process stopped.
	Prevent(prevent bool) Process

	// Restart send a restart signal to current process.
	Restart()

	// Start process with bio until stopped.
	Start(ctx context.Context) (err error)

	// Started return true if current process is started.
	Started() (yes bool)

	// StartedTime return time for Start() method called.
	StartedTime() time.Time

	// Starting return true if current process is starting.
	Starting() (yes bool)

	// Stop send a stop signal to current process.
	Stop()

	// Stopped return true if current process is stopped.
	Stopped() bool

	// Stopping return true if current process is stopping.
	Stopping() bool

	// StopWait block process until stopped.
	StopWait()
}
